package st.business.tepth.business.goods;

import io.reactivex.disposables.Disposable;
import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.config.Url;
import st.shadow.library.core.net.callback.IError;
import st.shadow.library.core.net.callback.ISuccess;
import st.shadow.library.core.net.rx.RxRestClient;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-02-25 15:38
 */

public class GoodsModel implements GoodsContract.Model {

    @Override
    public Disposable applyGoods(String token, String items,
                                 final OnDataConvertListener<String> listener) {
        return RxRestClient.builder()
                .url(Url.ApplyComsumable)
                .params("token", token)
                .params("items", items)
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        listener.convert(response);
                    }
                })
                .error(new IError() {
                    @Override
                    public void onError(int code, String msg) {
                        listener.error(code, msg);
                    }
                })
                .build()
                .post();
    }

    @Override
    public Disposable waiteApply(String token, String items,
                                 final OnDataConvertListener<String> listener) {
        return RxRestClient.builder()
                .url(Url.AddMaterialToWaiting)
                .params("token", token)
                .params("items", items)
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        listener.convert(response);
                    }
                })
                .error(new IError() {
                    @Override
                    public void onError(int code, String msg) {
                        listener.error(code, msg);
                    }
                })
                .build()
                .post();
    }
}
